package com.ylcy.ads.service;

import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import androidx.core.app.NotificationCompat;

import com.ylcy.ads.R;
import com.ylcy.ads.config.ENV;

public class RunningService extends Service {
    public RunningService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        //启用前台服务，主要是startForeground()
        Notification notification = new NotificationCompat.Builder(ENV.context, "alarm")
                .setAutoCancel(true)
                .setContentTitle("任务调度")
                .setContentText("任务调度APP将一直运行...")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon(R.mipmap.ic_launcher)
                //在build()方法之前还可以添加其他方法
                .build();
        //设置通知默认效果
        notification.flags = Notification.FLAG_SHOW_LIGHTS;
        startForeground(9, notification);

        ENV.intent = new Intent(ENV.context, BootService.class);
        ENV.context.startService(new Intent(ENV.context, RuleService.class));

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        stopForeground(true);
        super.onDestroy();
    }
}
